package com.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {
    public  static  String   toMd5(String  str) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        //加密之后的密文
        byte[] newPasswd = md5.digest(str.getBytes());
        //将密文转为32位的16进制的数字
        String result ="";
        for(byte b : newPasswd) {
            String temp = Integer.toHexString(b & 0xff);
            if (temp.length() == 1) {
                temp = "0" + temp;
            }
            result += temp;
        }
        return   result;
    }
}
